local js_yizheng = fk.CreateSkill {
  name = "js__yizheng",
}

js_yizheng:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#js__yizheng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, player, to_select, selected, selected_cards, card, extra_data)
    return #selected == 0 and to_select:getHandcardNum() > player:getHandcardNum() and player:canPindian(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target].winner == player then
      if not target.dead then
        room:setPlayerMark(target, "@@js__yizheng", 1)
      end
    else
      if player.dead or target.dead then return end
      local choice = room:askForChoice(target, {"0", "1", "2"}, self.name, "#js__yizheng-damage:"..player.id)
      if choice ~= "0" then
        room:doIndicate(target.id, {player.id})
        room:damage{
          from = target,
          to = player,
          damage = tonumber(choice),
          skillName = self.name,
        }
      end
    end
  end,
})
js_yizheng:addEffect(fk.EventPhaseChanging, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player == target and target:getMark("@@js__yizheng") > 0 and data.phase == Player.Draw
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@js__yizheng", 0)
    player:skip(Player.Draw)
    return true
  end,
})
return js_yizheng